package com.snopy.mq.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Send
 * @description
 * @email 77912204@qq.com
 * @date 2022/05/29 11:01
 */
public class Send {
    private final static String QUEUE_NAME = "hello";
    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("47.101.45.196");
        factory.setPort(5672);
        try(Connection connection = factory.newConnection();Channel channel = connection.createChannel();){
            channel.queueDeclare(QUEUE_NAME,false,false,false,null);
            String message = "Hello World Activemq!";
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes(StandardCharsets.UTF_8));
        } catch (IOException | TimeoutException e) {
            e.printStackTrace();
        }
    }
}
